<%@ taglib prefix="spring-tags" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="spring-form" uri="http://www.springframework.org/tags/form"%>
<%@ page
    import="java.util.Iterator"
    import="org.jiscinvolve.astrodabis.barberry.control.Paths"
    import="org.jiscinvolve.astrodabis.barberry.control.ObjectData"
    import="org.jiscinvolve.astrodabis.barberry.control.RequestData"
    import="org.jiscinvolve.astrodabis.barberry.common.core.Job"
    import="org.jiscinvolve.astrodabis.barberry.common.core.Tag"
    import="org.jiscinvolve.astrodabis.barberry.common.core.Account"
    session="true"
%><%
ObjectData<Tag> data = (ObjectData<Tag>) request.getAttribute(
    RequestData.MODEL_ATTRIB
    ) ;
Account actor = data.actor();
Tag tag  = data.object();
%>
<html>
    <head>
	    <title>AstroDAbis tag <%= tag.name() %></title>
        <link href='<%= data.file("css/page.css") %>' rel='stylesheet' type='text/css'/>
    </head>
    <body>
        <%@ include file="/jsp/header.jsp" %>
        <div class='body'>
            <div class='left'>
                <%@ include file="/jsp/menu.jsp" %>
            </div>
            <div class='right'>
                <a href='<%= data.link(tag) %>'>
                    <img src='<%= data.qrcode(data.link(tag)) %>'/>
                </a>
            </div>
            <div class='content'>
        	    <h2><%= tag.owner().name() %>&apos;s tag <%= tag.name() %></h2>
                <fieldset>
                    <legend>Tag details</legend>
                    <div>
                        <ul>
                            <li>
                                Owner : <a href='<%= data.link(tag.owner()) %>'><%= tag.owner().name() %></a>
                            </li>
                            <li>
                                Name : <%= tag.name() %>
                            </li>
                            <li>
                                Created : <%= tag.created() %>
                            </li>
                        </ul>
                    </div>
                    <%
                    if ((actor != null) && (actor.equals(tag.owner())))
                        {
                        %>
                        <form action='<%= data.link(tag, "delete") %>'>
    			            <button type="submit">delete</button>
                        </form>
                        <%
                        }
                    %>
                </fieldset>
                <fieldset>
                    <legend>Description</legend>
                    <div>
                        <%= tag.text() %>
                    </div>
                    <%
                    if ((actor != null) && (actor.equals(tag.owner())))
                        {
                        %>
                        <form action='<%= data.link(tag, "edit") %>'>
    			            <button type="submit">edit</button>
                        </form>
                        <%
                        }
                    %>
                </fieldset>
                <fieldset>
                    <legend>Row sets tagged with &apos;<%= tag.name() %>&apos;</legend>
                    <table>
                    <%
                    Iterator<Job> rowtags = tag.jobs().rowtags().iterator();
                    for (int i = 0 ; (i < 5) && rowtags.hasNext() ; i++)
                        {
                        Job job = rowtags.next();
                        %>
                        <tr>
                            <td>
                                <a href="<%= data.link(job) %>"><%= job.name() %></a>
                            </td>
                            <td>
                                <%= job.text() %>
                            </td>
                        </tr>
                        <%
                        }
                    %>
                    </table>
                </fieldset>

                <fieldset>
                    <legend>Join sets tagged with &apos;<%= tag.name() %>&apos;</legend>
                    <table>
                    <%
                    Iterator<Job> jointags = tag.jobs().jointags().iterator();
                    for (int i = 0 ; (i < 5) && jointags.hasNext() ; i++)
                        {
                        Job job = jointags.next();
                        %>
                        <tr>
                            <td>
                                <a href="<%= data.link(job) %>"><%= job.name() %></a>
                            </td>
                            <td>
                                <%= job.text() %>
                            </td>
                        </tr>
                        <%
                        }
                    %>
                    </table>

                </fieldset>
            </div>
        </div>
        <%@ include file="/jsp/footer.jsp" %>
    </body>
</html>

